package chai.ningning.creation;

import java.time.LocalDateTime;
import java.util.concurrent.*;

public class ExecutorTest2 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //创建一个线程池
        ExecutorService executorService = Executors.newFixedThreadPool(02);

        //通过创建 Callable 实例来指定一个线程任务 task
        Callable<Long> task = new Callable<Long>() {
            @Override
            public Long call() throws Exception {
                System.out.println(Thread.currentThread() +" : "+ LocalDateTime.now());
                return System.currentTimeMillis();
            }
        };

        //向线程池提交线程任务
        Future<Long> future = executorService.submit(task);
        System.out.println(future.get());

        //关闭线程池
        executorService.shutdown();
    }
}
